package com.lhg.service;

import com.lhg.mapper.ItemMapper;
import com.lhg.model.Item;
import com.lhg.model.User;
import com.lhg.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class ItemService {
    @Autowired
    private ItemMapper itemMapper;

    public List<Item> getUserItemByUid(Integer Uid) throws Exception {

        // 根据用户名获取用户信息
        List<Item> item = itemMapper.findItemByUid(Uid);
        if (item == null) {
            throw new Exception("暂无事项");
        }
        return item;
    }

    public void addItem(Item item) {
        item.setCreateDate(new java.sql.Date(new java.util.Date().getTime()));
        item.setStatus(false);
        itemMapper.insertItem(item);
    }

    public List<Integer> getItemIdByUid(Integer id) {
        List<Integer> itemIds = itemMapper.getItemIdByUid(id);
        return itemIds;
    }

    public Item getItemById(Integer taskId) {
        Item item = itemMapper.getItemById(taskId);
        return item;
    }

    public void updateItem(Item item1) {
        itemMapper.updateItem(item1);
    }
}
